<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>

<div id="app">
    <p>1. 原始写法</p>
    <p>{{firstName + "-" + lastName}}</p>
    <p>2. 函数写法</p>
    <p>{{getFullName()}}</p>
    <p>计算属性</p>
    <p>{{fullName}}</p>
</div>

<script src="../js/vue.js"></script>

<script>

    //计算属性 实现 setter() =>getter()
    //计算属性和函数的区别
    //1. 计算属性会缓存属性结果
    //2. 若多次调用,计算属性只会运算一次,而方法则是多次运算
    const app = Vue.createApp({
        data() {
            return {
                 firstName: "x",
                 lastName : "w"
             }
        },
        //细节: 本质上是属性,写法如函数,命名如属性
        computed:{
            fullName(){
                return this.firstName +"-"+this.lastName;
            }
        },
        methods: {
            getFullName(){
                return this.firstName + "-" + this.lastName;
            }
        },
    }).mount("#app");
</script>

</body>
</html>